﻿## Project: Lario
## Module: Language Choice
## Author: Salwan

import pygame
import pyenkido.gui.gui_manager
import pyenkido.entity
import pyenkido.controller
import pyenkido.screen_effects
import pyenkido.graphics
import pyenkido.font
import pyenkido.string_table

class LangChoiceScene(pyenkido.scene.Scene):
    def start(self):
        self.ticks = 0
        self.inputActivationTime = 30
        self.isInputActive = False
        self.fadeOutTime = 60
        self.isFadingOut = False
        self.sceneMgr.add_screen_effect(pyenkido.screen_effects.FadeEffect(self.screen, (0, 0, 0), True, 0, 60))
        # Enkido Bitmap Font
        self.enkFont= pyenkido.font.EnkidoFont("default.font")
        # Make it black
        self.enkFont.SetColorMask(False, False, False)
        # Menu
        self.cursor = 0
        # String table
        st = pyenkido.string_table.StringTable("res/game.strings", pyenkido.string_table.LANG_AR)

    def update(self):
        self.ticks += 1
        if not self.isInputActive:
            self.inputActivationTime -= 1
            if self.inputActivationTime <= 0:
                self.isInputActive = True
        if self.isFadingOut:
            self.fadeOutTime -= 1
            if self.fadeOutTime <= 0:
                self.sceneMgr.change_scene("MainMenu")

    def draw(self):
        self.screen.fill((0, 255, 255))
        pyenkido.graphics.draw_vertical_gradient_rect(self.screen, pygame.Rect(0, 0, 256, 240), (255, 156, 57), (255, 231, 132), 16)
        #self.font.DrawTextASCII(self.screen, (60, 75), "Choose Language:")
        pygame.draw.line(self.screen, (255, 255, 255), (0, 15), (256, 15), 2)
        self.enkFont.DrawTextASCII(self.screen, (4, 4), "Choose Language")
        self.enkFont.DrawTextArRL(self.screen, (172, 4), [113, 129, 121, 132, 0, 113, 159, 159, 151, 168])

        # Draw menu
        pygame.draw.rect(self.screen, (252, 230, 182), pygame.Rect(88, 93, 81, 40))
        pygame.draw.rect(self.screen, (255, 255, 255), pygame.Rect(88, 93, 81, 40), 1)
        self.enkFont.DrawTextASCII(self.screen, (104, 100), "English")
        self.enkFont.DrawTextArRL(self.screen, (104, 116), [113,159,147,132,119,171,168])
        # Cursor
        y = 0
        if self.cursor == 0:
            y = 100
        else:
            y = 116
        pygame.draw.polygon(self.screen, (255, 0, 0), [(94, y), (96, y), (100, y + 4), (96, y + 8), (94, y + 8)])
        pygame.draw.polygon(self.screen, (0, 0, 0), [(94, y), (96, y), (100, y + 4), (96, y + 8), (94, y + 8)], 1)

    def key_down(self, key):
        if not self.isInputActive:
            return
        if key == pygame.K_DOWN:
            self.cursor = 1
        elif key == pygame.K_UP:
            self.cursor = 0
        elif key == pygame.K_RETURN:
            self.sceneMgr.gamedb["lang"] = self.cursor
            self.isFadingOut = True
            self.sceneMgr.add_screen_effect(pyenkido.screen_effects.FadeEffect(self.screen, (0, 0, 0), False, 0, 60))


